import React from 'react';
import { Upload, message } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
import { useTranslation } from 'react-i18next';

interface ImageUploaderProps {
  onSuccess: (url: string) => void;
}

export const ImageUploader: React.FC<ImageUploaderProps> = ({ onSuccess }) => {
  const { t } = useTranslation();

  return (
    <Upload
      action="/api/upload"
      listType="picture"
      maxCount={1}
      onChange={({ file }) => {
        if (file.status === 'done') {
          message.success(t('upload.success'));
          onSuccess(file.response.url);
        } else if (file.status === 'error') {
          message.error(t('upload.error'));
        }
      }}
    >
      <UploadOutlined /> {t('upload.text')}
    </Upload>
  );
};